<?php
header('Access-Control-Allow-Origin:*');

$json = file_get_contents("user.json");

$arr = json_decode($json, true); 

$arr_usr = $arr["data"];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $usr = $_POST['usr'];
  $pwd = $_POST['pwd'];
  $is = true;
  foreach($arr_usr as $value) {
    if ($value['usr'] == $usr) {
      $is = false;
      echo 400;
    }
  }
  if ($is) {
    $get_usr = array("usr" => $usr, "pwd" => $pwd);
    array_push($arr_usr, $get_usr);
    $arr['data'] = $arr_usr;
    $json = json_encode($arr, true);
    file_put_contents("user.json", $json);
    echo 200;
  }
} 
